package util;

import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import enums.AdapterEnum;

public class PatternPlainTextParser extends PatternParser{
	
String separator;
	
	public PatternPlainTextParser(String separator){
		super();
		this.separator = separator;
	}
	
	public Map<String,Set<Enum>> parse(String... filenames) throws DocumentException, ClassNotFoundException{
		
		
		for(String filename :filenames){
			File file = new File(filename);
			//the first line is roles of a pattern. e.g., Target, Adapter, Adaptee		
			try {
				BufferedReader br
				   = new BufferedReader(new FileReader(file));
				
				String  thisLine = null;
				
				String firstLine = br.readLine();
				String[] title=firstLine.split(separator);
				//by default: this is Adapter
				while ((thisLine = br.readLine()) != null) {
					String[] strs=thisLine.split(separator);
				    addPatternType(strs[0],AdapterEnum.Target);
				    addPatternType(strs[1],AdapterEnum.Adapter);
				    addPatternType(strs[2],AdapterEnum.Adaptee);
				 }
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
		
		return patternTypeMap;
	}
}
